package com.wudl.core

import org.apache.spark.{SparkConf, SparkContext}

/**
 * MapPartions 一次只处理一个分区的数，而map 是一次处理一个元素
 */
object SparkMapPartitions {
  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setMaster("local[1]").setAppName("SparkMapPartitions")
    val sc = new SparkContext(conf)
    val rdd = sc.makeRDD(1 to (4), 2)

    val mapParRdd = rdd.mapPartitions(x => x.map(_ * 2))
    mapParRdd.collect().foreach(println)

    sc.stop()


  }


}
